%igetx.m

% gets x,  given a, b, and sig.
% also gets xNs
% also needs Ti(i)  (in isetup)
% x_i = [Sum_{t \in T(i)} b_t(y_it-a_t) ] / [Sum_t b_t^2]

x = zeros(Nx,1);
% Ti = zeros(Nx,1);  already got Ti -- in isetup 

for r=1:kx,
  if bbon(ka+kb+r) == 1,
    rind= find(i==r);
    if length(rind)==1,
      Sumx = ( y(rind) - aNs(rind) )*bNs(rind);
      Sumb = bNs(rind)^2;
    else
      rind1=zeros(Ns,1);
      rind1(rind)=OneNs(rind); ;
      Sumx = rind1'*((y-aNs).*bNs);
      Sumb = (rind1.*bNs)'*bNs;
    end;
    x(r) = Sumx/Sumb;
  end;
end;

igetxns;
